package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public void addBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        //创建人
        bed.setCreateBy(1L);
        bed.setUpdateBy(1L);
        //创建时间
        bed.setCreateTime(LocalDateTime.now());
        bed.setUpdateTime(LocalDateTime.now());
        bed.setBedStatus(0);
        bedMapper.addBed(bed);
    }

    @Override
    public BedVo getBedsByBedId(Long id) {
        Bed bed = bedMapper.getBedsByBedId(id);
            BedVo bedVo = new BedVo();
            BeanUtils.copyProperties(bed,bedVo);
            return bedVo;
    }

    @Override
    public void updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        bed.setUpdateBy(1L);
        bed.setUpdateTime(LocalDateTime.now());
        bed.setBedStatus(bedDto.getBedStatus());
        bedMapper.updateBed(bed);
    }

    @Override
    public BedVo delete(Long id) {
        bedMapper.delete(id);
        return null;
    }

}

